package com.example.demo.controller;

import com.example.demo.model.Book;
import com.example.demo.model.User;
import com.example.demo.service.TypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 功能描述：
 *
 * @Author: Zhanghf
 * @Date: 2021/5/22 11:27
 */
@Controller
public class TypeController {
    @Autowired
    private TypeService typeService;
    @GetMapping(value = "classify")
    public String type(HttpServletResponse response, HttpServletRequest request, Model model, HttpSession session) {
        //热门推荐
        String type = request.getParameter("type");
        List<Book> latestover = null;
        List<Book> latestupdate = null;
        typeService.classify(type,latestover,latestupdate,model);
        if (type.equals("index")) {
            return "redirect:/index";
        }
        User user = (User) session.getAttribute("user");
        model.addAttribute("user", user);
        return "type";
    }
}
